package com.dongdongshop.controller;

import com.dongdongshop.data.PageResult;
import com.dongdongshop.data.Result;
import com.dongdongshop.domain.rep.BrandReq;
import com.dongdongshop.domain.rep.SpecificationReq;
import com.dongdongshop.domain.rep.TypeTemplateReq;
import com.dongdongshop.domain.res.TypeTemplateRes;
import com.dongdongshop.service.TemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "东东商城模板管理")
@RefreshScope
@RequestMapping("temp")
public class TemplateController {
    @Autowired
    private TemplateService templateService;

    /**
     * 模板分页查询
     * @param templateReq
     * @return
     */
    @ApiOperation("模板分页查询")
    @PostMapping("queryPage")
    public Result<PageResult> queryPage(@RequestBody TypeTemplateReq templateReq){
        PageResult pageResult=templateService.queryPage(templateReq);
        return Result.success(pageResult);
    }

    /**
     * 模板增加修改操作
     * @param templateReq
     * @return
     */
    @PutMapping("save")
    @ApiOperation("模板增加修改操作")
    public Result save(@RequestBody TypeTemplateReq templateReq) {
        templateService.save(templateReq);
        return Result.success();
    }

    /**
     * 模板删除操作
     * @param id
     * @return
     */
    @DeleteMapping("delete/{id}")
    @ApiOperation("模板删除操作")
    public Result delete(@PathVariable("id") Long id){
        templateService.delete(id);
        return Result.success();
    }


    /**
     * 模板批量删除操作
     * @param ids
     * @return
     */
    @PatchMapping("batchRemove")
    @ApiOperation("模板批量删除操作")
    public Result batchRemove(@RequestBody List<Integer> ids){
        templateService.batchRemove(ids);
        return Result.success();
    }

    @GetMapping("queryByItemId/{itemId}")
    public Result<TypeTemplateRes> queryByItemId(@PathVariable("itemId") Long itemId){
        TypeTemplateRes templateRes =templateService.queryByItemId(itemId);
        return Result.success(templateRes);
    }
}
